package com.A21.Adapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;

import android.app.Activity;
import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.A21.Object.A21CustomerPrice;
import com.A21.Object.MSTProduct;
import com.A21MobileSales.Common;
import com.A21MobileSales.R;
import com.A21MobileSales.TrnProductDetails;

public class CustomerProductPriceAdapter extends BaseAdapter {
	ViewHolder holder;
	LayoutInflater inflater;
	ArrayList<A21CustomerPrice>  lstProducts;
	ArrayList<A21CustomerPrice>  mOriginalValues;
	private Context context;

	public CustomerProductPriceAdapter() {
		// TODO Auto-generated constructor stub
	}
	Common objC;
	String Code;
	public CustomerProductPriceAdapter(Context _context,
			ArrayList<A21CustomerPrice>  _lstProducts,String _Code) {
		Activity act = (Activity) _context;
		this.context = _context;
		this.Code=_Code;
		this.lstProducts = _lstProducts;
		this.mOriginalValues = new ArrayList<A21CustomerPrice> ();
		this.mOriginalValues.addAll(lstProducts);
		inflater = (LayoutInflater) act
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
	}

	public int getCount() {
		return lstProducts.size();
	}

	public Object getItem(int arg0) {
		return lstProducts.get(arg0);
	}

	public long getItemId(int arg0) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View vi = convertView;
		if (convertView == null) {
			vi = inflater.inflate(R.layout.row_customer_product, null);
			holder = new ViewHolder();
			holder.tvProduct = (TextView) vi.findViewById(R.id.tvProduct);
			holder.tvPName = (TextView) vi.findViewById(R.id.tvPName);
			holder.tvPriceType = (TextView) vi.findViewById(R.id.tvPriceType);
			holder.tvCurrency = (TextView) vi.findViewById(R.id.tvCurrency);
			holder.tvPrice = (TextView) vi.findViewById(R.id.tvPrice);
			vi.setTag(holder);
		} else {
			holder = (ViewHolder) vi.getTag();
		}
		try {  
			
			holder.tvProduct.setText(lstProducts.get(position).Product);
			holder.tvPName.setText(lstProducts.get(position).PName);  
			holder.tvPriceType.setText(lstProducts.get(position).PType);
			holder.tvCurrency.setText(lstProducts.get(position).Currency);
			holder.tvPrice.setText(lstProducts.get(position).UPrice);
			
		} catch (Exception ex) {
			ex.printStackTrace();
		}

		return vi;
	}

	private class ViewHolder {
		TextView tvProduct;
		TextView tvPName;
		TextView tvPriceType;
		TextView tvCurrency;
		TextView tvPrice;
	}

	public void filter(String charText) {
		charText = charText.toLowerCase(Locale.getDefault());
		lstProducts.clear();
		if (charText.length() == 0) {
			lstProducts.addAll(mOriginalValues);
		} else {
			for (A21CustomerPrice pc : mOriginalValues) {
				final String Product = pc.Product;
				final String ProductName = pc.PName;
				if (Product.toLowerCase().contains(
						charText.toString().toLowerCase())
						|| ProductName.toLowerCase().contains(
								charText.toString().toLowerCase())) {
					lstProducts.add(pc);
				}
			}
		}
		notifyDataSetChanged();
	}

}